package com.hooya.fa.eu.biz.dao.mapper.stk;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hooya.fa.eu.api.bo.PlatformZyInfoBO;
import com.hooya.fa.eu.biz.dao.entity.TempZyjl;
import com.hooya.fa.eu.biz.dao.entity.dto.TransferRecordDTO;
import com.hooya.fa.eu.biz.dao.entity.dto.ZyDataDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description 1
 * @Author : Zongz
 * @Copyright Copyright (c) 豪雅集团
 * @Create 2024/3/18
 * @Version 1.0.0
 */
@Mapper
@DS("fa_eu")
public interface TempZyjlMapper extends BaseMapper<TempZyjl> {

    void insertBatchSomeColumn(List<TempZyjl> list);

	@DS("fa_eu_daily")
	void insertBatchSomeColumnDaily(List<TempZyjl> list);

    /**
     * 获取所有costway的转运记录（包括历史）
     *
     * @return list
     */
    @Select("select cpbh sku, zcck, zlck place, tobelongs belongs, 0 num, cgsl zySl, hthm, htrq, frombelongs, tobelongs from temp_zyjl " +
            "where frombelongs regexp 'COSTWAY-' and tobelongs regexp 'COSTWAY-' and zlck != 'EU生资库' and cgsl != 0 " +
            "union all " +
            "select cpbh sku, zcck, zlck place, to_belongs belongs, 0 num, sl zySl, hthm, htrq, from_belongs, to_belongs from fa_eu_his.temp_zyjl " +
            "where from_belongs regexp 'COSTWAY-|GLOBALWAY' and to_belongs regexp 'COSTWAY-|GLOBALWAY' and zlck != 'EU生资库' and sl != 0")
    List<PlatformZyInfoBO> getAllCostwayZyList();

	@Select("SELECT sum(cgsl) as sl, cpbh, zcck, zlck, htrq as date, frombelongs, tobelongs FROM fa_eu.temp_zyjl WHERE htrq >= #{startDate} AND htrq < #{endDate} AND cpbh <> #{excludedCpbh} GROUP BY cpbh,zcck,zlck,htrq,frombelongs,tobelongs")
	List<TransferRecordDTO> getZyjlData(@Param("startDate") String startdate, @Param("endDate")String endDate, @Param("excludedCpbh")String excludedCpbh);

	List<ZyDataDTO> getZyInData(@Param("start") String start, @Param("end") String end);

	List<ZyDataDTO> getZyOutData(@Param("start") String start, @Param("end") String end);

	List<ZyDataDTO> getZyFirstDay(@Param("start") String start, @Param("end") String end);
}
